{extend name="base" /}
{block name="content"}
<div class="m-b-md">
    {if condition="input('param.bid')"}
    <h2 class="m-b-none">品牌编辑</h2>
    {else/}
    <h2 class="m-b-none">品牌添加</h2>
    {/if}
</div>
<form class="form-horizontal" id="form" action="" method="post">
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="form-group">
                <label for="" class="col-sm-2 control-label">品牌名称</label>
                <div class="col-sm-9">
                    <input type="text" name="bname" value="{$oldData['bname']}" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-sm-2 control-label">品牌排序</label>
                <div class="col-sm-9">
                    <input type="text" name="sort" value="{$oldData['sort']}" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-sm-2 control-label">品牌热门</label>
                <div class="col-sm-9">
                    <input type="radio" name="hot" value="1" {if condition="$oldData['hot']==1" } checked{/if}>是
                    <input type="radio" name="hot"  value="2" {if condition="$oldData['hot']==2" } checked{/if}>否
                </div>
            </div>
            <div class="form-group">
                <label for="" class="col-sm-2 control-label">品牌LOGO</label>
                <div class="col-sm-9">
                    <div class="col-sm-10">
                        <div class="input-group">
                            <input type="text" class="form-control" name="logo" readonly="" value="{$oldData['logo']}">
                            <div class="input-group-btn">
                                <button onclick="upImage(this)" class="btn btn-default" type="button">选择图片</button>
                            </div>
                        </div>
                        <div class="input-group" style="margin-top:5px;">
                                <img src="{$oldData['logo']}" class="img-responsive img-thumbnail" width="150">
                            <em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="removeImg(this)">×</em>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <button class="btn btn-primary" type="submit">确定提交</button>
</form>
</div>
<script>
    //上传图片
    function upImage(obj) {
        require(['util'], function (util) {
            options = {
                multiple: false,//是否允许多图上传
                //data是向后台服务器提交的POST数据
                data:{name:'后盾人',year:2099},
            };
            util.image(function (images) {          //上传成功的图片，数组类型 
                $("[name='logo']").val(images[0]);
                $(".img-thumbnail").attr('src', images[0]);
            }, options)
        });
    }

    //移除图片
    function removeImg(obj) {
        $(obj).prev('img').attr('src', '__PUBLIC__/Admin/images/nopic.jpg');
        $(obj).parent().prev().find('input').val('');
    }
</script>
{/block}